package com.example.gulimall.coupon.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.common.utils.LocalDateTimeUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;

import com.example.gulimall.coupon.dao.SeckillSessionDao;
import com.example.common.entity.coupon.SeckillSessionEntity;
import com.example.gulimall.coupon.service.SeckillSessionService;


@Service("seckillSessionService")
public class SeckillSessionServiceImpl extends ServiceImpl<SeckillSessionDao, SeckillSessionEntity> implements SeckillSessionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SeckillSessionEntity> page = this.page(
                new Query<SeckillSessionEntity>().getPage(params),
                new QueryWrapper<SeckillSessionEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SeckillSessionEntity> uploadSecKillSkuLatestConditionDay(int day) {
        String[] times = LocalDateTimeUtils.calcConditionDay(day);
//        return this.baseMapper.selectList(
//                Wrappers.<SeckillSessionEntity>lambdaQuery()
//                .between(SeckillSessionEntity::getStartTime, times[0], times[1])
//        );
        return this.baseMapper.selectUploadSecKillSkuLatestConditionDay(times[0], times[1]);
    }

}